import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";

// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
  const env = loadEnv(mode, process.cwd(), "");
  // console.log("defineConfig", env);
  return {
    define: {
      __APP_ENV__: env.APP_ENV
    },
    resolve: {
      alias: {
        "@": path.resolve(__dirname, "src")
      }
    },
    plugins: [
      vue(),
      AutoImport({
        resolvers: [ElementPlusResolver()]
      }),
      Components({
        resolvers: [ElementPlusResolver()]
      })
    ],
    css: {
      preprocessorOptions: {
        less: {
          modifyVars: {},
          javascriptEnabled: true
        }
      }
    },
    server: {
      host: '192.168.45.32', // 或 'localhost' 或你的机器的实际 IP 地址
      port: 3001,
      hmr: true, // 确保 HMR 被启用
      watch: {
        usePolling: true, // 强制使用轮询来监控文件变化
      },
      // host: "192.168.45.26",
      // port: 8080,
      //
      // proxy: {
      //   [env.VITE_APP_BASE_API]: {
      //     target: env.VITE_APP_BASE_URL,
      //     changeOrigin: true,
      //     rewrite: path => path.replace(env.VITE_APP_BASE_API, "")
      //   }
      // }
    }
  };
});
